using System;
using System.Web.UI;
using Resources;

/// <summary>
/// ///
/// ///    Notes exceptions, exclusions, or any other funny's you need 
/// ///    to know about CaseFromEmail
/// ///
/// Liquid Thought
/// Created by:Rihan
/// 
/// </summary>
public partial class CaseFromEmail : Page
{
    private string _emailId;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadQueryString();
        }

        CrmCase caseBeingConverted = new CrmCase();

        Email emailBeingConverted = new Email();
        emailBeingConverted.EmailId = new Guid(_emailId);
        emailBeingConverted.Load();

        caseBeingConverted.SourceEmail = emailBeingConverted;
        caseBeingConverted.Create();
        caseBeingConverted.attachEmail();
        caseBeingConverted.DetachEmailFromQueue();


        Response.Redirect("../cs/cases/edit.aspx?id={" + caseBeingConverted.IncedentId.ToString() + "}");
    }

    /// <summary>
    /// Converts the case.
    /// </summary>
    /// <param name="emailId">The email id.</param>
    /// <returns></returns>
    private string ConvertCase()
    {
        Case convertCase = new Case();
        string caseid = "";
        caseid = convertCase.ConvertCrmEmailIntoIncident(_emailId).ToString();
        return caseid;
    }

    /// <summary>
    /// Loads the query string.
    /// </summary>
    private void loadQueryString()
    {
        if (Request.QueryString.Count > 0)
        {
            _emailId = Request.QueryString[Resource.QueryStringParameterId].ToString();
        }
    }
}